/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.maternity.componentes.menu;

import java.util.List;

/**
 *
 * @author Aluno
 */
public class MenuItem{
	private String name;
	private String link;
        private List<MenuItem> children;

	public MenuItem(String _name, String _link, List<MenuItem> _children){
		name = _name;
		link = _link;
                children = _children;
	}

	public String render(boolean selected){
		String item ;
                boolean hasChildren = false;
                if(getChildren() != null) {
                hasChildren = !children.isEmpty();
            }
                
		if(selected){
                    if(hasChildren) {
                        item = "<li class='has-sub '>";
                    }
                    else {
                        item = "<li class='active '>";
                    }
                }
                else{
                    if(hasChildren) {
                        item = "<li class='has-sub '>";
                    }
                    else {
                        item = "<li>";
                    }
                }

		item += "<a href='" + getLink() + "' ><span>" + getName() + "</span></a>";
                if(hasChildren){
                    item += "<ul>";
                    for(MenuItem child : children){
                        item += child.render(selected);
                    }
                    item += "</ul>";
                }
		item += "</li>";

		return item;
	}

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the link
     */
    public String getLink() {
        return link;
    }

    /**
     * @return the children
     */
    public List<MenuItem> getChildren() {
        return children;
    }
}
